<html>

<head>
	<!--stylesheet-->
	<link rel="stylesheet" type="text/css" href="style.css" />
	
	<!--jquery ui css-->
	<link type="text/css" href="jquery/css/sunny/jquery-ui-1.8rc3.custom.css" rel="stylesheet" />

	<!--jquery-->
	<script type="text/javascript" src="jquery/js/jquery-1.4.2.min.js"></script>

	<!--jquery ui js-->
	<script type="text/javascript" src="jquery/js/jquery-ui-1.8rc3.custom.min.js"></script>
				
	<!--validation js-->
	<script type="text/javascript" src="jquery-validate/jquery.validate.js"></script>
		
	<!--tablesorter js-->
	<script type="text/javascript" src="jquery/tablesorter/tablesorter.js"></script>
		
	<!--tablesorter css-->
	<link rel="stylesheet" type="text/css" href="jquery/tablesorter/css/style2.css" />
		
	<script type="text/javascript" src="jquery/development-bundle/external/jquery.bgiframe-2.1.1.js"></script>
	<script type="text/javascript" src="jquery/development-bundle/ui/jquery.ui.core.js"></script>
	<script type="text/javascript" src="jquery/development-bundle/ui/jquery.ui.widget.js"></script>
	<script type="text/javascript" src="jquery/development-bundle/ui/jquery.ui.datepicker.js"></script>
	<script type="text/javascript" src="jquery/development-bundle/ui/jquery.ui.dialog.js"></script>

	<script type="text/javascript" src="jquery/development-bundle/ui/jquery.effects.core.js"></script>
	<script type="text/javascript" src="jquery/development-bundle/ui/jquery.effects.fold.js"></script>

		<script type="text/javascript">	
//CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--
//AddClientView--------------------------------------------------------------------------
			function retrieveAllClients(){					
					flag="retrieveAllClients";
					$.post('AddClientController.php',{
						flag:flag
						},function(data){
							$('#list').html(data);
							$('#list').show('fold', {size:51}, 1000);
						}
					);
			}
			
			function addClient(from){
				if(from=="edit"){
					company = $("#companyValue").val();
					address = $("#addressValue").val();
					emailAdd = $("#emailAddValue").val();
					cellNo = $("#cellNoValue").val();
					telNo = $("#telNoValue").val();
					faxNo = $("#faxNoValue").val();		
					$.post('clientForm.php',{
						company: company,
						address: address, 
						emailAdd: emailAdd,
						cellNo: cellNo,
						telNo: telNo,
						faxNo: faxNo
						},function(data){
							$('#view').html(data);
						}
					);
				}
				else{			
					$('#view').fadeOut(250,function(){
						$('#view').load('clientForm.php');
					});
					$('#view').fadeIn(500);
				}
			}
			
			function addNewClient(from_i){
					company = $("#companyValue").val();
					address = $("#addressValue").val();
					emailAdd = $("#emailAddValue").val();
					cellNo = $("#cellNoValue").val();
					telNo = $("#telNoValue").val();
					faxNo = $("#faxNoValue").val();
					flag=from_i;
					$.post('AddClientController.php',{
						company: company,
						address: address,
						emailAdd: emailAdd,
						cellNo: cellNo,
						telNo: telNo,
						faxNo: faxNo,
						flag:flag
						},function(data){
							$('#view').html(data);
						}
					);
					if(from=="confirm")
						retrieveAllClients();
			}

//AddClientView--------------------------------------------------------------------------

//EditClientView--------------------------------------------------------------------------
				function validate(from){
					flag=0;
					if(from=="addClient" || from=="editClient"){
						//client = $("#clientValue").val();
						company = $("#companyValue").val();
						address = $("#addressValue").val();
						emailAdd = $("#emailAddValue").val();
						cellNo = $("#cellNoValue").val();
						telNo = $("#telNoValue").val();
						faxNo = $("#faxNoValue").val();
						
						if(company==""){
							$("#companyError").css({'display':'inline'})
							flag=1;
						}
						else
							$("#companyError").css({'display':'none'})
						if(address==""){
							$("#addressError").css({'display':'inline'})
							flag=1;
						}
						else
							$("#addressError").css({'display':'none'})
						if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailAdd))
							$("#emailAddError").css({'display':'none'})
						else{
							$("#emailAddError").css({'display':'inline'})
							flag=1;
						}
						if(cellNo==""){
							$("#cellNoError").css({'display':'inline'})
							flag=1;
						}
						else
							$("#cellNoError").css({'display':'none'})
						if(telNo==""){
							$("#telNoError").css({'display':'inline'})
							flag=1;
						}
						else
							$("#telNoError").css({'display':'none'})
						if(faxNo==""){
							$("#faxNoError").css({'display':'inline'})
							flag=1;
						}				
						
						else
							$("#faxNoError").css({'display':'none'})
						if(flag==0){
							if(from=="addClient")
								addNewClient('submit');
							else if(from=="editClient")
								editSelectedClient('submit');
						}
					}
					else{
						client = $("#clientValue").val();
						name = $("#nameValue").val();
						origin = $("#originValue").val();
						date = $("#dateValue").val();
						if(client==0){
							$("#clientError").css({'display':'inline'})
							flag=1;
						}
						else
							$("#clientError").css({'display':'none'})
						if(name==""){
							$("#nameError").css({'display':'inline'})
							flag=1;
						}
						else
							$("#nameError").css({'display':'none'})
						if(origin==""){
							$("#originError").css({'display':'inline'})
							flag=1;
						}
						else
							$("#originError").css({'display':'none'})
						if(date==""){
							$("#dateError").css({'display':'inline'})
							flag=1;
						}
						else
							$("#dateError").css({'display':'none'})
						
						if(flag==0){
							if(from=="addEnzyme")
								addNewEnzyme('submit');
							else if(from=="editEnzyme"){
								editSelectedEnzyme('submit');
							}
						}
					}
				}

				function selectClient(client_i){
					$('#view').fadeOut(250, function(){
						client = client_i;
						flag = "selectClient";
						$.post('EditClientController.php',{
							client: client,
							flag:flag
							},function(data){
								$('#view').html(data);
							}
						);
					});
					$('#view').fadeIn(500);
				}
				
				function editClientForm(from_i){

					client2 = $("#clientValue").val();
					
					company2 = $("#companyOrig").val();
					address2 = $("#addressOrig").val();
					emailAdd2 = $("#emailAddOrig").val();
					cellNo2 = $("#cellNoOrig").val();
					telNo2 = $("#telNoOrig").val();
					faxNo2 = $("#faxNoOrig").val();
				

					company = $("#companyValue").val();
					address = $("#addressValue").val();
					emailAdd = $("#emailAddValue").val();
					cellNo = $("#cellNoValue").val();
					telNo = $("#telNoValue").val();
					faxNo = $("#faxNoValue").val();

					from = from_i;					

					$.post('editClientForm.php',{

						client: client2,
						companyOrig: company2, 
						addressOrig: address2,
						cellNoOrig: cellNo2,
						telNoOrig:telNo2,
						faxNoOrig:faxNo2,
						emailAddOrig:emailAdd2,
						
						company: company, 
						address: address,
						cellNo: cellNo,
						telNo:telNo,
						faxNo:faxNo,
						emailAdd:emailAdd,
						
						from:from
						
						},function(data){
							$('#view').html(data);
						}
					);
				}
				
				function editSelectedClient(from){

					client = $("#clientValue").val();				

					company2 = $("#companyOrig").val();
					address2 = $("#addressOrig").val();
					emailAdd2 = $("#emailAddOrig").val();
					cellNo2 = $("#cellNoOrig").val();
					telNo2 = $("#telNoOrig").val();
					faxNo2 = $("#faxNoOrig").val();
					
					company = $("#companyValue").val();
					address = $("#addressValue").val();
					emailAdd = $("#emailAddValue").val();
					cellNo = $("#cellNoValue").val();
					telNo = $("#telNoValue").val();
					faxNo = $("#faxNoValue").val();
										
					if(from=="submit")
						flag="submit";
					else if(from=="confirm")
						flag="confirm";
					else if(from=="edit")
						flag="edit";					
					
					$.post('EditClientController.php',{

						client: client,

						companyOrig: company2, 
						addressOrig: address2,
						cellNoOrig: cellNo2,
						telNoOrig:telNo2,
						faxNoOrig:faxNo2,
						emailAddOrig:emailAdd2,
						
						company: company, 
						address: address,
						cellNo: cellNo,
						telNo:telNo,
						faxNo:faxNo,
						emailAdd:emailAdd,
						
						flag:flag
						},function(data){
							$('#view').html(data);
						}
					);
					if(from=="confirm"){
						$("#dialog").html("You have successfuly edited "+client);
						$("#dialog").dialog({
							resizable: false,
							modal: true,
							show:'blind',
							hide:'blind',
							buttons: {
								"Okay": function() {
									$(this).dialog('close');
								}
							}
						});
						retrieveAllClients();
					}
					
				}
				
				function highlight(count){
					$("#inner1"+count).css({'background-color':'yellow'});
				}
				function unhighlight(count){
					if(count%2==0)
						$("#inner1"+count).css({'background-color':'white'});
					else
						$("#inner1"+count).css({'background-color':'#e7e7e7'});
				}
				
				function cancel(from){
					if(from=="client"){
						client = $("#clientValue").val();
						company = $("#companyOrig").val();
						address = $("#addressOrig").val();
						emailAdd = $("#emailAddOrig").val();
						cellNo = $("#cellNoOrig").val();
						telNo = $("#telNoOrig").val();
						faxNo = $("#faxNoOrig").val();
						from = "view";
						$.post('viewClientInfo.php',{
							client: client,
							company: company, 
							address: address,
							cellNo: cellNo,
							telNo: telNo,
							faxNo: faxNo,
							emailAdd: emailAdd,
							from: from
							},function(data){
								$('#view').html(data);
							}
						);
					}
					else if(from=="enzyme"){
						client = $("#clientOrig").val();
						name = $("#nameOrig").val();
						origin = $("#originOrig").val();
						date = $("#dateOrig").val();
						from = "view";
						$.post('viewEnzymeInfo.php',{
							client: client,
							name: name, 
							origin: origin,
							date: date,
							from: from
							},function(data){
								$('#view').html(data);
							}
						);
					}
					else
						$("#view").fadeOut(500,function(){
							$("#view").html("");						
						});
					

				}
//EditClientView--------------------------------------------------------------------------
//CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--CLIENT--

			$(document).ready(function(){ 
					$("#myTable").tablesorter(); 
			}); 

			$(function() {
				$("#dateValue").datepicker();
			});


			function retrieveAllEnzymes(){
					flag="retrieveAllEnzymes";
					$.post('AddEnzymeController.php',{
						flag:flag
						},function(data){
							$('#list').html(data);
							$('#list').show('fold', {size:51}, 1000);
						}
					);
			}

			function addEnzyme(from){
				if(from=="edit"){
					client = $("#clientValue").val();
					name = $("#nameValue").val();
					origin = $("#originValue").val();
					date = $("#dateValue").val();
					$.post('enzymeForm.php',{
						client: client,
						name: name, 
						origin: origin,
						date: date
						},function(data){
							$('#view').html(data);
						}
					);
				}
				else{
					$('#view').fadeOut(250,function(){
						$('#view').load('enzymeForm.php');
					});
					$('#view').fadeIn(500);
				}
			}
			
			function addNewEnzyme(from_i){
					client = $("#clientValue").val();
					name = $("#nameValue").val();
					origin = $("#originValue").val();
					date = $("#dateValue").val();
					flag=from_i;
					$.post('AddEnzymeController.php',{
						client: client,
						name: name,
						origin: origin,
						date: date,
						flag:flag
						},function(data){
							$('#view').html(data);
						}
					);	
					if(from_i=="confirm")
						retrieveAllEnzyme();
			}

			function selectEnzyme(client_i,name_i){
				$('#view').fadeOut(250, function(){
					client = client_i;
					name = name_i;
					flag = "selectEnzyme";
					$.post('EditEnzymeController.php',{
						client: client,
						name: name,
						flag: flag
						},function(data){
							$('#view').html(data);
						}
					);
				});
				$('#view').fadeIn(500);
			}
			
			function editEnzymeForm(from_i){
			
					client2 = $("#clientOrig").val();
					name2 = $("#nameOrig").val();
					origin2 = $("#originOrig").val();
					date2 = $("#dateOrig").val();			

					client = $("#clientValue").val();
					name = $("#nameValue").val();
					origin = $("#originValue").val();
					date = $("#dateValue").val();
					
					from = from_i;					

					$.post('editEnzymeForm.php',{

				
						clientOrig: client2, 
						nameOrig: name2,
						originOrig: origin2,
						dateOrig:date2,
						
						client: client, 
						name: name,
						origin: origin,
						date:date,
						
						from:from
						
						},function(data){
							$('#view').html(data);
						}
					);
				}
				
			function editSelectedEnzyme(from){
					
					client2 = $("#clientOrig").val();
					name2 = $("#nameOrig").val();
					origin2 = $("#originOrig").val();
					date2 = $("#dateOrig").val();
					
					client = $("#clientValue").val();
					name = $("#nameValue").val();
					origin = $("#originValue").val();
					date = $("#dateValue").val();
						
					if(from=="submit")
						flag="submit";
					else if(from=="confirm")
						flag="confirm";
					else if(from=="edit")
						flag="edit";					
					
					$.post('EditEnzymeController.php',{

						clientOrig: client2, 
						nameOrig: name2,
						originOrig: origin2,
						dateOrig:date2,
						
						client: client, 
						name: name,
						origin: origin,
						date:date,
						
						flag:flag
						},function(data){
							$('#view').html(data);
						}
					);
					if(from=="confirm"){
						$("#dialog").html("You have successfuly edited "+clientOrig);
						$("#dialog").dialog({
							resizable: false,
							modal: true,
							show:'blind',
							hide:'blind',
							buttons: {
								"Okay": function() {
									$(this).dialog('close');
								}
							}
						});
						retrieveAllEnzymes();
					}
					
				}
			
			

//CHANGE-INTERFACE--------------------------------------------------------------------------
			
			function change(from){
		//CLIENT--------------------------------------------------------------------------
				if(from=="client"){
					$("#view").fadeOut(500);
					$("#mainContent").html("<div id=\"list\"></div><div id=\"view\"></div>");
					retrieveAllClients();					
				}				
		//CLIENT--------------------------------------------------------------------------

		//ENZYME--------------------------------------------------------------------------				
				else if(from=="enzyme"){
					$("#view").fadeOut(500);
					$("#mainContent").html("<div id=\"list\"></div><div id=\"view\"></div><div id=\"clientMessage\"></div>");
					retrieveAllEnzymes();
				}
		//ENZYME--------------------------------------------------------------------------

		//PROCEDURE--------------------------------------------------------------------------
				else if(from=="procedure"){
					$("#main").fadeOut(500, function(){
						$("#mainContent").html("");
						location.hash = "Enzyme";
						$('#mainContent').append("<iframe src=\"selectProcedure.php\" width=\"1010px\" height=\"500px\" >");
					});
					$("#main").fadeIn(750);
					$("#mainContentDiv").css('height','650px');
					$("#main").css('height','650px');
				}
		//PROCEDURE--------------------------------------------------------------------------
			}
//CHANGE-INTERFACE--------------------------------------------------------------------------
			
//SEARCH--------------------------------------------------------------------------
			function clearMain(){
				$("#mainContent").html("");
			}
			
			function search(){
				option = $('#searchOption').val();
				search_i = $('#search_i').val();
				searchTemp = search_i.split(" ");
				searchFinal = searchTemp.join("+%+");
	
				$("#mainContent").html("");

				if(option=="client"){
					$.post('SearchClientController.php',{
						search: searchFinal
						},function(data){
							$('#mainContent').html(data);
						}
					);
				}
				else{
					$.post('SearchEnzymeController.php',{
						search: searchFinal
						},function(data){
							$('#mainContent').html(data);
						}
					);
				}				
				
			}
//SEARCH--------------------------------------------------------------------------

			function showDialog(){

				from = $("#addButton").val();

				if(from == "Add")
					$("#dialog").load("clientForm.html");
				else if(from == "Add Enzyme")
					$("#dialog").html("Add Enzyme");

				$("#dialog").dialog({
					resizable: false,
					modal: true,
					show: 'fold',
					hide: 'fold',
					title:from
				});	
			}


//Allan's code
		</script>	

</head>

<body>

	<div id="menu">
		<span id="client" onclick="change('client');return false;">
			Client
		</span>
		<span id="enzyme" onclick="change('enzyme');return false;">
			Enzyme
		</span>
		<span id="procedure" onclick="change('procedure');return false;">
			Procedure
		</span>
		<span id="search">
			<input type="text" id="search_i" size="30" onkeyup="search();return false;"/>
			<select id="searchOption" onchange="clearMain();">
				<option value="client">Client</option>
				<option value="enzyme">Enzyme</option>
			</select>
		</span>
	</div>
	
	<div id="mainContent">
	
		<div id="list">
		
			<div id="lHead">
				<span id="listHeader">CLIENTS</span>
			</div>
			<div id="lBody">
			</div>
			<div id="lLower">
			
			</div>
		
		</div>
		
		<div id="view">
			<div id="vHead">
				<span id="viewHeader">CLIENT INFORMATION</span>
			</div>
			<div id="vBody">
			</div>
			<div id="vLower">
			
			</div>
		</div>
		
	</div>

	<div id="dialog">
	
	</div>

</body>

</html>